import Vue from 'vue'
import App from './App.vue'
import router from './router'

//引入饿了么UI
import ElementUI from 'element-ui'
//引入饿了么CSS
import 'element-ui/lib/theme-chalk/index.css';

//组成饿了么组件
Vue.use(ElementUI)

//引入axios
import axios from 'axios'
//挂载axios到vue原型
Vue.prototype.$axios = axios
//设置基准路径
axios.defaults.baseURL = "http://127.0.0.1:3000"


//全局后置守卫
router.beforeEach((to, from, next) => {
  //如果去往的路径不是登录页，或者没有token值，则拦截然后返回登录页
  if (to.path != '/login' && !localStorage.getItem('token')) {
    router.push('/login')
  } else {
    //放行
    next()
  }
})


Vue.config.productionTip = false

new Vue({
  router,
  render: function (h) { return h(App) }
}).$mount('#app')
